/*
 * @Author: your name
 * @Date: 2022-01-10 17:33:59
 * @LastEditTime: 2022-01-10 17:46:59
 * @LastEditors: Please set LastEditors
 * @Description: 服务器
 * @FilePath: \human resource\server.js
 */

const Koa = require('koa')
const serve = require('koa-static');
const { historyApiFallback } = require('koa2-connect-history-api-fallback');
const path = require('path')
const app = new Koa();
// 这句话 的意思是除接口之外所有的请求都发送给了 index.html
app.use(historyApiFallback({
    whiteList: ['/prod-api']
})); // 这里的whiteList是 白名单的意思
app.use(serve(__dirname + "/dist")); //将public下的代码静态化

const proxy = require('koa2-proxy-middleware')

app.use(proxy({
    targets: {
        // (.*) means anything
        '/prod-api/(.*)': {
            target: 'http://ihrm-java.itheima.net/api', //后端服务器地址
            changeOrigin: true,
            pathRewrite: {
                '/prod-api': ""
            }
        }
    }
}))
const port = 9898
app.listen(port, () => {
    console.log('服务器启动成功')
    console.log(`http://localhost:${port}`)
})